function e(r) {
    r = r.replace(/\r\n/g, `
`);
    for (var i = "", o = 0; o < r.length; o++) {
        var a = r.charCodeAt(o);
        a < 128 ? i += String.fromCharCode(a) : a > 127 && a < 2048 ? (i += String.fromCharCode(a >> 6 | 192),
            i += String.fromCharCode(a & 63 | 128)) : (i += String.fromCharCode(a >> 12 | 224),
            i += String.fromCharCode(a >> 6 & 63 | 128),
            i += String.fromCharCode(a & 63 | 128))
    }
    return i
}
var t = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
function encode(r) {
    var i = "", o, a, s, u, c, l, p, g = 0;
    for (r = e(r); g < r.length;)
        o = r.charCodeAt(g++),
            a = r.charCodeAt(g++),
            s = r.charCodeAt(g++),
            u = o >> 2,
            c = (o & 3) << 4 | a >> 4,
            l = (a & 15) << 2 | s >> 6,
            p = s & 63,
            isNaN(a) ? l = p = 64 : isNaN(s) && (p = 64),
            i = i + t.charAt(u) + t.charAt(c) + t.charAt(l) + t.charAt(p);
    return i
}

console.log(encode("123456"))